package com.company.manage.system.entity;

import com.company.manage.common.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Created by HuangYong on 2016/1/22.
 * desc:
 */
@Entity
@Table(name = "t_role")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicInsert
@DynamicUpdate
public class Role extends BaseEntity {
    private static final String TAG = "Role";


    private static final long serialVersionUID = 2399849236746954407L;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)
    private Integer id;
    @Column(name = "NAME", nullable = false, length = 20)
    private String name;
    @Column(name = "ROLE_CODE", nullable = false, length = 20)
    private String roleCode;
    @Column(name = "DESCRIPTION", length = 65535)
    private String description;
    @Column(name = "SORT")
    private Short sort;
    @Column(name = "DEL_FLAG", length = 1)
    private String del_Flag;

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
    private Set<UserRole> userRoles = new HashSet<UserRole>();
    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
    private Set<RolePermission> rolePermissions= new HashSet<RolePermission>();

    public Role() {
    }

    public Role(Integer id) {
        this.id = id;
    }

    public Role(String name, String roleCode) {
        this.name = name;
        this.roleCode = roleCode;
    }

    public Role(Integer id, String name, String roleCode, String description, Short sort, String del_Flag, Set<UserRole> userRoles, Set<RolePermission> rolePermissions) {
        this.id = id;
        this.name = name;
        this.roleCode = roleCode;
        this.description = description;
        this.sort = sort;
        this.del_Flag = del_Flag;
        this.userRoles = userRoles;
        this.rolePermissions = rolePermissions;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoleCode() {
        return roleCode;
    }

    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Short getSort() {
        return sort;
    }

    public void setSort(Short sort) {
        this.sort = sort;
    }

    public String getDel_Flag() {
        return del_Flag;
    }

    public void setDel_Flag(String del_Flag) {
        this.del_Flag = del_Flag;
    }

    public Set<UserRole> getUserRoles() {
        return userRoles;
    }

    public void setUserRoles(Set<UserRole> userRoles) {
        this.userRoles = userRoles;
    }

    public Set<RolePermission> getRolePermissions() {
        return rolePermissions;
    }

    public void setRolePermissions(Set<RolePermission> rolePermissions) {
        this.rolePermissions = rolePermissions;
    }
}